﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.IO;

namespace Celeriq.Core.HostTest
{
	class Program
	{
		static void Main(string[] args)
		{
			var configuration = Celeriq.Utilities.ConfigurationSettings.GetInstance();

			if (!Directory.Exists(configuration.DataPath))
				Directory.CreateDirectory(configuration.DataPath);

			var baseAddress = new Uri("net.tcp://localhost:1973/__celeriq_core");
			var service = new Celeriq.Graphing.Core.SystemCore();
			var host = new ServiceHost(service, baseAddress);

			//Initialize the service
			var myBinding = new NetTcpBinding();
			myBinding.Security.Mode = SecurityMode.Transport;

			host.AddServiceEndpoint(typeof(Celeriq.Graphing.Core.ISystemCore), myBinding, string.Empty);
			host.Open();

			//Create Core Listener
			var myEndpoint = new EndpointAddress(host.BaseAddresses.First().AbsoluteUri);
			var client = new ChannelFactory<Celeriq.Graphing.Core.ISystemCore>(myBinding, myEndpoint);
			var _core = client.CreateChannel();

			Console.WriteLine("Press <Enter> to stop the service.");
			Console.ReadLine();

			_core.ShutDown();

		}
	}
}
